#include <stdlib.h>
#include <GL/glut.h>
#include "Grid.h"


Grid::Grid()
: _total(10)
{

	/*red=240;
	green=128;
	blue=128;*/

	red=250;
	green=0;
	blue=250;
	mostrar=true;


}

void Grid::aumentar()
{
	_total++;
}
void Grid::disminuir()
{
	_total--;
}
void Grid::renderTrayectoria(unsigned int ventana) const
{
	
	if(!mostrar)return;

	const float sep = ventana/(float)_total; // Distance between lines
	glColor3f(red, green, blue);
	glBegin(GL_LINES);
	int extra=ventana/2;
	for( unsigned int i = 0; i < _total; ++i)
	{
		// horizontal
		glVertex2f(-extra,i*sep);
		glVertex2f(ventana/2, i*sep);
		// vertical
		glVertex2f(i*sep-ventana/2,0);
		glVertex2f(i*sep-ventana/2, ventana);
	}
	glEnd();
}

void Grid::renderFigura(unsigned int ventana) const
{

	if(!mostrar)return;


	const float sep = ventana/(float)_total; // Distance between lines
	glColor3f(red, green, blue);
	glBegin(GL_LINES);
	int extra=ventana/2;
	for( unsigned int i = 0; i < _total; ++i)
	{
		// horizontal
		//glVertex2f((-ventana/2),(ventana/2)+i*sep);
		//glVertex2f(ventana/2,(-ventana/2)+i*sep);
		//// vertical
		//glVertex2f(i*sep-ventana/2,ventana/2);
		//glVertex2f(i*sep-ventana/2,-ventana/2);
	
		//hori
		glVertex2f(-extra,i*sep-extra);
		glVertex2f(ventana/2, i*sep-extra);
		// vertical
		glVertex2f(i*sep-ventana/2,-extra);
		glVertex2f(i*sep-ventana/2, ventana/2);


	}
	glEnd();

	//glColor3f(0.9f, 0, 0);
	//glLineWidth(3.0f);
	//glBegin(GL_LINES);
	//glVertex2f(-ventana+10, 10);
	//glVertex2f(ventana-10, 10);
	//glEnd();

}

void Grid::menuMostrar()
{
	mostrar=true;
}
void Grid::menuEsconder()
{
	mostrar=false;
}

void Grid::cambiarColor(float r, float g, float b)
{
	red=r;
	green=g;
	blue=b;

}
